package com.paradogs.common.utils;

import com.alibaba.fastjson2.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author: yumi
 * @date: 2024/3/28  14:04
 * @Description: TODO
 */
@Data
public class R<T> {

    private int code;
    private String message;
    private T data;

    public static int SUCCESS_CODE = 0;
    public static int FAIL_CODE = -1;

    public R(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /** 成功 */
    public static <T> R<T> success(String message) {
        return new R<>(SUCCESS_CODE, message, null);
    }
    public static <T> R<T> success(T data) {
        return new R<>(SUCCESS_CODE, "success", data);
    }
    public static <T> R<T> success() {
        return new R<>(SUCCESS_CODE, "success", null);
    }

    /** 失败 */
    public static <T> R<T> fail(String message) {
        return new R<>(FAIL_CODE, message, null);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
